<?php
/**
 * pagination
 */
class PagerAHelper
{
	static function split($count, $pagesize=null, $url_param=array())
	{
		$tmp		=	array();
		$tmp['key']	=	Core::cfg('page_key');
		
		$page		=	Lib::request($tmp['key'], 'int', '1');
		if($page <1) $page=1;
		if(!$pagesize) $pagesize=Core::cfg('page_size');
		
		$tmp['p_total']		=	ceil($count/$pagesize);
		$tmp['p_offset']	=	$page<$tmp['p_total']?$page:$tmp['p_total'];
		$tmp['p_size']		=	$pagesize;
		
		$tmp['r_total']		=	$count;
		$tmp['r_offset']	=	$pagesize * ($page-1);
		
		$url_param		=	array_diff_key(array_merge($_GET, $_POST, $url_param), array($tmp['key']=>null));
		$tmp['url']		=	"./?a={$_REQUEST['a']}".($url_param?'&'.http_build_query($url_param):'');
		
		View::pushVar('pager',	$tmp);
		return $tmp;
	}
	
}
?>